<template>
	<view class="body-bar">
		<view class="avatar-bar">
			<image src="/static/icons/weixin.png" mode=""></image>
		</view>
		<text style="font-size:32rpx;color: #333;font-weight: 450;display: inline-block;margin: 90rpx 0 40rpx;">
			申请获取以下权限
		</text>
		<text
			style="font-size:32rpx;color: #999999;font-weight: 450;display: inline-block;margin-bottom: 90rpx;">获得你的公开信息(昵称、头像等)</text>
		<button class="weixin-button" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">授权登录</button>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		loginByWeixinApi
	} from '../../api/login';

	// 获取手机号
	function onGetPhoneNumber(event) {
		uni.login({
			success(res) {
				loginByWeixinApi({
						iv: event.detail.iv,
						encryptedData: event.detail.encryptedData,
						code: res.code,
						appId: 'wx6be369f8c028cf56',
						appSecret: 'c83698330c18f797d14fc56bec3f709f'
					})
					.then(res => {
						if (res.code == 200) {
							uni.setStorageSync('user_token', res.token);
							uni.switchTab({
								url: '/pages/home/home'
							})
							userStore.getUserInfo()
						}
					})
			}
		})
	}
</script>

<style scoped>
	.body-bar {
		display: flex;
		flex-direction: column;
		width: 650rpx;
		height: 100vh;
		margin: 0 auto;
	}

	.avatar-bar {
		height: 360rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		border-bottom: 1px solid #999;
	}

	.avatar-bar image {
		margin-top: 120rpx;
		height: 160rpx;
		width: 160rpx;
	}

	.weixin-button {
		background-color: #00be30;
		width: 100%;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		border-radius: 40rpx;
		color: #fff;
		font-size: 40rpx;
		font-weight: 500;
	}
</style>